'use strict';

const Controller = require('egg').Controller;
const { ObjectId } = require("mongodb");
class SubjectController extends Controller {
  async index() {
      const { ctx } = this;
      console.log(ctx.params);
      try {
          var { id } = ctx.params;
          var db = this.app.mongodb;
          var res = await db.collection("article").find({ _id: ObjectId(id) }).toArray();
          console.log(res);
          ctx.body = {
              status: 200,
              res
          }
      } catch (err) {
        //   console.log(err);
          ctx.status = 400;
          ctx.body = {
              status: 400,
              msg:"输入的id值不合法"
          }
      }
  }
}

module.exports = SubjectController;
